from fastapi import APIRouter, Depends

from backend.app.app.api.api_Xiong.crud.pub_crud import read_oilstim_result_db, save_oilstim_result_db, \
    read_oilstim_planproj_forecast_db, save_oilstim_planproj_forecast_db
from backend.app.app.api.api_Xiong.models.x_model import read_oilstim_result_model, save_oilstim_result_model, \
    save_oilstim_planproj_forecast_model, read_oilstim_planproj_forecast_model
from backend.app.app.api.api_v1.user import verify_token_user

tab_router = APIRouter(prefix="/tab", tags=["tab"])

@tab_router.post("/readtab1",name="读tab1库")
def read_oilstim_result(datas: read_oilstim_result_model, ver=Depends(verify_token_user)):
    result = read_oilstim_result_db(datas.data)
    return {
        'result': result,
        'verify': ver
    }

@tab_router.post("/savetab1",name="存tab1库")
def save_oilstim_result(datas: save_oilstim_result_model, ver=Depends(verify_token_user)):
    result = save_oilstim_result_db(datas.delete, datas.add, datas.modify)
    return {
        'result': result,
        'verify': ver
    }

@tab_router.post("/readtab4",name="读tab4库")
def read_oilstim_planproj_forecast(datas: read_oilstim_planproj_forecast_model, ver=Depends(verify_token_user)):
    result = read_oilstim_planproj_forecast_db(
        datas.DvpUnit_Name,
        datas.StimType_Name,
        datas.Start_Year,
        datas.End_Year
    )
    return {
        'result': result,
        'verify': ver
    }

@tab_router.post("/savetab4",name="存tab4库")
def save_oilstim_planproj_forecast(datas: save_oilstim_planproj_forecast_model, ver=Depends(verify_token_user)):
    result = save_oilstim_planproj_forecast_db(datas.delete, datas.add, datas.modify)
    return {
        'result': result,
        'verify': ver
    }